/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

#include "DeleteComponentCommand.h"

#include <QUndoCommand>
#include <QStringList>

#include "../EntityExplorer.h"
#include "../Entity.h"
#include "../LevelMaster2000.h"

DeleteComponentCommand::DeleteComponentCommand( EntityExplorer* entityExplorer,
                                                QString entityName,
                                                QString componentName,
                                                QString className,
                                                QString componentXML,
                     QUndoCommand *parent )
                         : QUndoCommand( parent ),
                         entityExplorer( entityExplorer ),
                         entityName( entityName ),
                         componentName( componentName ),
                         className( className ),
                         componentXML( componentXML )
{
    init();
}

void DeleteComponentCommand::init()
{
    setText( "Delete Component \"" + componentName + "\"" );
}

void DeleteComponentCommand::undo()
{
    LevelMaster2000::DISALLOW_NEW_COMMAND++;
    {
        //TODO: this assumes the correct components are selected.
        //Is this a given fact?
        entityExplorer->createComponent( componentName, className );
        entityExplorer->setComponentXml( entityName, componentName, componentXML );
//        entityExplorer->createEntity( name, group );
//        entityExplorer->setEntityXml( name, entityXML );
    }
    LevelMaster2000::DISALLOW_NEW_COMMAND--;
}

void DeleteComponentCommand::redo()
{
    LevelMaster2000::DISALLOW_NEW_COMMAND++;
    {
        entityExplorer->deleteComponent( entityName, componentName );
//        entityExplorer->removeEntityFromSelection( entityExplorer->findEntity( name ) );
//        entityExplorer->updateLastSelection();
//        entityExplorer->deleteEntity( name );
    }
    LevelMaster2000::DISALLOW_NEW_COMMAND--;
}
